package cn.itcast.bos.web.action.system;

import java.io.IOException;
import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.service.system.PermissionService;
import cn.itcast.bos.web.action.common.BaseAction;

@Namespace("/")
@ParentPackage("struts-default")
@Controller
@Scope("prototype")
public class PermissionAction extends BaseAction<Permission> {
	private static final long serialVersionUID = 1L;
	@Autowired
	private PermissionService permissionService;

	// 分页查询
	@Action("permission_list")
	public void list() throws IOException {

		List<Permission> permissions = permissionService.findAll();
		String jsonString = JSONArray.toJSONString(permissions, SerializerFeature.DisableCircularReferenceDetect);
		ServletActionContext.getResponse().setContentType("application/json;charset=utf-8");
		ServletActionContext.getResponse().getWriter().write(jsonString);

	}

	// 添加
	@Action(value = "permission_save", results = {
			@Result(name = "success", location = "./pages/system/permission.html", type = "redirect") })
	public String save() {
		permissionService.save(model);
		return SUCCESS;
	}
}
